//
//  AGLStoreViewController.m
//  CateyeMovie
//
//  Created by dllo on 16/4/29.
//  Copyright © 2016年 anguoli. All rights reserved.
//

#import "AGLStoreViewController.h"
#import "Header.h"
#import "DataBaseTool.h"
#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height

@interface AGLStoreViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableView;

@end

@implementation AGLStoreViewController



- (void)viewWillAppear:(BOOL)animated {
    if (self.tableView != nil) {
        [self.tableView reloadData];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.translucent = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 40)];
    titleLabel.text = @"我的收藏";
    titleLabel.textColor = [UIColor whiteColor];
    self.navigationItem.titleView = titleLabel;
    
    [self createTable];
}

- (void)createTable {
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [[DataBaseTool shareDataBase] allModelIsExistInMovieTable].count ;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *reuse = @"storeReuse";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse];
    }
    cell.textLabel.text =  [[DataBaseTool shareDataBase] allModelIsExistInMovieTable][indexPath.row][@"ft"];
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    

    NSString *scid = [[DataBaseTool shareDataBase] allModelIsExistInMovieTable][indexPath.row][@"scid"];
    VideoDetailViewController *vidoeDetailVC = [[VideoDetailViewController alloc] init];
    vidoeDetailVC.scid = scid;
    //                vidoeDetailVC.videoURL = [NSURL URLWithString:videoURLStr];
    vidoeDetailVC.videoURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://gslb.miaopai.com/stream/%@.mp4", scid]];
    vidoeDetailVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vidoeDetailVC animated:YES];
    vidoeDetailVC.hidesBottomBarWhenPushed = NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
